<template>
	<el-dialog :title="titleMap[mode]" v-model="visible" :width="1500" destroy-on-close @closed="$emit('closed')" align-center>
        <el-container>
            <el-header>
                <div class="left-panel">
                <el-button type="primary" icon="el-icon-plus" @click="add" v-auth="'receivable.add'"></el-button>
                </div>
                <div class="right-panel">
                    <div class="right-panel-search">
                        <el-input style="margin:5px 10px" v-model="search.project_code" placeholder="请输入项目编号" clearable @keyup.enter="upsearch"></el-input>
                        <el-input style="margin:5px 10px" v-model="search.metting" placeholder="请输入项目名称" clearable @keyup.enter="upsearch"></el-input>
                        <!-- <el-select v-model="search.collect_status" placeholder="请选择回款状态" clearable>
                            <el-option label="全部" :value="0"/>
                            <el-option label="未回款" :value="1"/>
                            <el-option label="部分回款" :value="2"/>
                            <el-option label="回款完成" :value="3"/>
                        </el-select> -->
                        <el-button type="primary" icon="el-icon-search" @click="upsearch">搜索</el-button>
                        <el-button type="primary" icon="el-icon-refresh" @click="refresh">重置</el-button>
                    </div>
                </div>
            </el-header>
            <el-main class="nopadding">
                <scTable ref="table" row-key="id" :apiObj="apiObj" remoteSort remoteFilter border height="600" :params="query" :cell-style="cellStyle">
                    <el-table-column width="1"></el-table-column>
                    <el-table-column type="selection" width="50" reserve-selection align="center"></el-table-column>
                    <el-table-column label="公司名称" prop="project.customer.company_name" align="center"></el-table-column>
                    <el-table-column label="项目编号" prop="project.project_code" align="center"></el-table-column>
                    <el-table-column label="项目名称" prop="project.metting" align="center"></el-table-column>
                    <el-table-column label="会议类型" prop="project.type" align="center">
                        <template #default="scope">
                            <div v-if="scope.row.project">
                                <div v-if="scope.row.project.type == 1">会议</div>
                                <div v-if="scope.row.project.type == 2">婚礼</div>
                                <div v-if="scope.row.project.type == 3">会议代收</div>
                                <div v-if="scope.row.project.type == 4">会议代收+自付</div>
                                <div v-if="scope.row.project.type == 5">赞助</div>
                            </div>
                        </template>
                    </el-table-column>
                    <el-table-column label="应收金额" prop="collect_account" align="center"></el-table-column>
                    <el-table-column label="已回金额" prop="return_account" align="center"></el-table-column>
                    <el-table-column label="未回款金额" prop="not_account" align="center"></el-table-column>
                    <el-table-column label="回款状态" prop="collect_status" align="center">
                        <template #default="scope">
                            <div v-if="scope.row.collect_status == 1">未回款</div>
                            <div v-if="scope.row.collect_status == 2">部分回款</div>
                            <div v-if="scope.row.collect_status == 3">回款完成</div>
                        </template>
                    </el-table-column>
                    <el-table-column label="计划回款时间" prop="plan_time" align="center"></el-table-column>
                    <el-table-column label="未回款说明" prop="not_remark" align="center"></el-table-column>
                    <el-table-column label="项目日期" prop="project.project_time" align="center"></el-table-column>
                    <el-table-column label="创建日期" prop="create_time" align="center"></el-table-column>
                </scTable>
            </el-main>
        </el-container>
		<template #footer>
			<el-button @click="visible = false">取 消</el-button>
		</template>
	</el-dialog>
    <save-add v-if="dialog.save" ref="saveDialog" @success="handleSuccess" @closed="dialog.save=false"></save-add>
</template>

<script>
import saveAdd from './save.vue'
export default {
    props:{
        query: { type: String, default: "" },
    },
    components: { saveAdd },
	emits: ['success', 'closed'],
	data() {
		return {
			mode: "add",
			titleMap: {
				add: '选择项目',
				edit: '编辑产品',
				show: '查看'
			},
			visible: false,
			isSaveing: false,
			apiObj: this.$API.project.receivable.list,
			selection: [],
			search: {
				project_code: null,
				metting: null,
				collect_status: null,
			},
            dialog: {
				save: false,
			},
		}
	},
	mounted() {
	},
	methods: {
        cellStyle(row){
            let cellStyle = '';
            switch(row.row.project&&row.row.project.type){
                case 3:
                    cellStyle = {color:'#000',backgroundColor:'#ff4a09'}
                    break;
                case 4:
                    cellStyle = {color:'#000',backgroundColor:'#f5971c'}
                    break;
                case 5:
                    cellStyle = {color:'#000',backgroundColor:'#67c23a'}
                    break;
                default:
                    cellStyle = {color:'#000',backgroundColor:'#ffffff'}
            }
            return cellStyle
        },
		//显示
		open(mode = 'add') {
			this.mode = mode;
			this.visible = true;
			return this
		},
		//表单注入数据
		setData(data) {
			//可以和上面一样单个注入，也可以像下面一样直接合并进去
            this.form.id = data.id
		},
        //搜索
		upsearch() {
			this.$refs.table.upData(this.search)
		},
        refresh(){
            for (const key in this.search) {
                this.search[key] = null;
            }
            this.$refs.table.upData(this.search)
        },
        selectionChange() {
			// this.$emit('success', selection)
            // this.visible = false;
		},
        //客户新增
		add() {
			this.dialog.save = true
			this.$nextTick(() => {
				this.$refs.saveDialog.open('add')
			})
		},
        // 更新客户新增
        handleSuccess(data, mode) {
			if (mode == 'add') {
				this.$refs.table.refresh()
			} else if (mode == 'edit') {
				this.$refs.table.refresh()
			}
		},
	}
}
</script>

<style></style>
